<?php
namespace Model;


use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Predicate\Like;
use Zend\Db\Sql\Predicate\Operator;
use Zend\Db\Sql\Select;


class RouteTable extends AbstractTable implements LanguageAwareInterface
{
    /**
     * @var
     */
    private $_lang;

    /**
     * @param $id
     * @return Route
     */
    public function getRoute($id){
       return $this->getById($id);
    }

    /**
     * @param $name
     * @return Route
     */
    public function getRouteByName($name)
    {
       return $this->getByColumn('name', $name)->current();
    }


    /**
     * @param string $route
     * @return Route
     */
    public function getRouteByRoute($route)
    {
        return $this->getByColumn('route', $route)->current();
    }

    /**
     * @param string $pageId
     * @return Route
     */
    public function getRouteByPageId($pageId)
    {
        return $this->getByColumn('page_id', $pageId)->current();
    }


    public function getLang()
    {
        return $this->_lang;
    }

    public function setLang($lang)
    {
        $this->_lang = $lang;
    }

    public function getAll(){
        return $this->getTableGateway()->select(array('lang'=>$this->_lang));
    }

    public function getAllWithPageInfo(){
        $select = $this->getDbSqlSelect();
        $select->join(array('p'=>'page'), 'p.id = route.page_id',
            array('module'=>'module', 'controller'=>'controller', 'action'=>'action'));
//        ->where(array('lang'=>$this->_lang));
        return $this->getTableGateway()->selectWith($select);
    }
}